Skip to content

[fix](be) Harden JNI reader split lifecycle#65503

Merged
Gabriel39 merged 5 commits into
apache:masterfrom
Gabriel39:agent/fix-jni-reader-contracts
Jul 13, 2026
Merged

[fix](be) Harden JNI reader split lifecycle#65503
Gabriel39 merged 5 commits into
apache:masterfrom
Gabriel39:agent/fix-jni-reader-contracts

Conversation

@Gabriel39

@Gabriel39 Gabriel39 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

JNI-backed file scans had several lifecycle, compatibility, and adaptive-batching gaps:

  • The scan-level FileScannerV2 selector cannot inspect split-level JNI metadata. It could therefore route legacy Paimon JNI splits—especially old-FE splits without reader_type—to a scanner that cannot dispatch them.
  • A cancelled query could continue requesting Java batches when every row in the current batches was filtered out.
  • JNI open or close failures could discard cleanup state or mark the outer scanner closed too early, preventing retained Java resources from being cleaned up on a retry.
  • Adaptive batch-size changes did not consistently reach already-open JNI scanners and Paimon/Hudi hybrid readers. Paimon's physical reader cannot be resized after open, so accepting a later logical update could make the reported batch size diverge from the actual reader.
  • End-of-split state could be lost after the JNI scanner closed, making repeated reads after EOF non-idempotent.
  • Paimon options and Hadoop configuration supplied at split level were not retained as mixed-version fallback values.

This PR hardens those paths by:

  • conservatively keeping scan-level JNI compatibility shapes on the legacy scanner and rejecting unsupported Paimon C++ ranges in FileScannerV2;
  • checking cancellation before fetching another Java batch;
  • preserving JNI cleanup state after failures, retaining each Paimon Java resource until its cleanup succeeds, and allowing scanner-level close to retry table-reader cleanup;
  • seeding the adaptive probe before eager JNI open, forwarding supported batch-size updates to open JNI and hybrid readers, and preserving Paimon's initial physical batch size after open;
  • preserving EOF state across scanner cleanup; and
  • applying explicit precedence between current scan-level Paimon settings and split-level rolling-upgrade fallbacks.

Release note

Harden JNI table-reader lifecycle handling, adaptive batching, and rolling-upgrade compatibility for Paimon and Hudi scans.

Check List

  • Added comments for scanner-selection, lifecycle, adaptive-batch, and compatibility invariants.
  • Added focused unit tests covering cancellation, EOF idempotence, cleanup failure and retry, adaptive batching, scanner selection, and Paimon fallback precedence.
  • Passed 30 focused ASAN BE unit tests from FileScannerV2Test.*, JniTableReaderTest.*, and PaimonJniReaderTest.* after addressing the latest review.
  • Passed all 10 PaimonJniScannerTest Java tests; checkstyle reported 0 violations.
  • Passed build-support/check-format.sh and git diff --check.
  • Ran changed-file clang-tidy; analysis is blocked by the existing toolchain missing stddef.h and pre-existing repository diagnostics.

### What problem does this PR solve?

JNI-backed table readers could violate scanner selection, cancellation, cleanup, EOF, adaptive batching, and rolling-upgrade contracts.

Issue Number: N/A

Related PR: N/A

### Release note

Harden JNI table-reader lifecycle handling and compatibility for Paimon and Hudi scans.

### Check List

- [x] Added unit tests for the fixes
- [x] Added comments for compatibility and lifecycle invariants
- [x] Passed 45 focused ASAN BE unit tests
- [x] Passed repository format and diff checks
@Gabriel39 Gabriel39 requested a review from yiguolei as a code owner July 12, 2026 14:15
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: You've hit your usage limit. Visit https://chatgpt.com/codex/settings/usage to purchase more credits or try again at 5:19 PM.
Workflow run: https://github.com/apache/doris/actions/runs/29195932553

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: You've hit your usage limit. Visit https://chatgpt.com/codex/settings/usage to purchase more credits or try again at 5:19 PM.
Workflow run: https://github.com/apache/doris/actions/runs/29196846018

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 30004 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit f4dd46c9839e89e245846a4a58308e8de5482540, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17707	4099	4333	4099
q2	2026	341	209	209
q3	10274	1417	850	850
q4	4686	471	339	339
q5	7499	879	564	564
q6	179	172	139	139
q7	771	905	625	625
q8	9317	1557	1569	1557
q9	5652	4438	4430	4430
q10	6757	1796	1564	1564
q11	511	349	317	317
q12	699	566	439	439
q13	18086	3399	2767	2767
q14	263	259	240	240
q15	q16	791	783	711	711
q17	1000	999	1054	999
q18	7483	5624	5630	5624
q19	1306	1214	1069	1069
q20	768	613	554	554
q21	6383	2896	2581	2581
q22	460	367	327	327
Total cold run time: 102618 ms
Total hot run time: 30004 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	5080	4753	4897	4753
q2	318	320	213	213
q3	5084	5272	4566	4566
q4	2076	2133	1396	1396
q5	5016	4662	4765	4662
q6	224	187	136	136
q7	1863	1698	1580	1580
q8	2519	2354	2206	2206
q9	7751	7339	7255	7255
q10	4627	4585	4145	4145
q11	539	402	356	356
q12	736	740	530	530
q13	2953	3396	2712	2712
q14	274	284	249	249
q15	q16	685	695	600	600
q17	1297	1272	1274	1272
q18	7347	7040	6870	6870
q19	1117	1086	1041	1041
q20	2228	2186	1960	1960
q21	5313	4604	4489	4489
q22	531	473	415	415
Total cold run time: 57578 ms
Total hot run time: 51406 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 180273 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit f4dd46c9839e89e245846a4a58308e8de5482540, data reload: false

query5	4310	646	481	481
query6	452	226	201	201
query7	4831	594	336	336
query8	350	195	175	175
query9	8762	4102	4078	4078
query10	457	356	310	310
query11	5960	2394	2135	2135
query12	160	103	99	99
query13	1252	602	409	409
query14	6205	5282	4970	4970
query14_1	4254	4261	4269	4261
query15	207	206	179	179
query16	1034	464	435	435
query17	923	742	560	560
query18	2469	458	344	344
query19	200	184	142	142
query20	115	106	103	103
query21	228	154	131	131
query22	13631	13530	13380	13380
query23	17379	16516	16159	16159
query23_1	16319	16353	16306	16306
query24	7572	1797	1300	1300
query24_1	1332	1311	1309	1309
query25	588	466	398	398
query26	1330	351	217	217
query27	2636	587	387	387
query28	4436	2035	2064	2035
query29	1092	645	503	503
query30	338	267	231	231
query31	1131	1093	984	984
query32	111	66	61	61
query33	536	331	268	268
query34	1179	1201	665	665
query35	787	789	659	659
query36	1411	1386	1205	1205
query37	152	111	95	95
query38	1899	1693	1650	1650
query39	929	935	876	876
query39_1	902	875	881	875
query40	254	165	141	141
query41	71	71	70	70
query42	95	95	93	93
query43	326	342	295	295
query44	1502	802	782	782
query45	205	188	181	181
query46	1092	1226	791	791
query47	2364	2365	2180	2180
query48	419	411	306	306
query49	601	434	323	323
query50	1130	415	331	331
query51	10978	10940	10902	10902
query52	89	90	77	77
query53	276	284	205	205
query54	309	261	228	228
query55	77	74	70	70
query56	313	316	291	291
query57	1414	1402	1314	1314
query58	297	278	255	255
query59	1594	1640	1464	1464
query60	326	282	269	269
query61	192	147	138	138
query62	702	640	581	581
query63	242	202	204	202
query64	2826	1056	866	866
query65	4880	4729	4775	4729
query66	1795	508	389	389
query67	29771	29409	29312	29312
query68	3105	1545	1035	1035
query69	398	306	260	260
query70	1033	960	954	954
query71	372	335	320	320
query72	3103	2771	2384	2384
query73	806	805	433	433
query74	5100	4980	4740	4740
query75	2621	2595	2233	2233
query76	2313	1190	764	764
query77	360	383	283	283
query78	12298	12432	11704	11704
query79	1380	1201	780	780
query80	1298	541	450	450
query81	527	315	274	274
query82	594	161	125	125
query83	403	323	295	295
query84	322	157	127	127
query85	976	641	509	509
query86	422	298	280	280
query87	1832	1821	1727	1727
query88	3727	2837	2790	2790
query89	454	405	359	359
query90	1932	203	201	201
query91	211	193	165	165
query92	65	69	55	55
query93	1572	1521	976	976
query94	721	363	324	324
query95	769	578	465	465
query96	1048	834	364	364
query97	2670	2676	2541	2541
query98	219	202	197	197
query99	1139	1185	1026	1026
Total cold run time: 266138 ms
Total hot run time: 180273 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24.99 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit f4dd46c9839e89e245846a4a58308e8de5482540, data reload: false

query1	0.01	0.00	0.01
query2	0.10	0.05	0.05
query3	0.26	0.14	0.14
query4	1.61	0.14	0.14
query5	0.24	0.24	0.23
query6	1.34	1.06	1.09
query7	0.04	0.01	0.01
query8	0.06	0.03	0.04
query9	0.39	0.32	0.31
query10	0.60	0.56	0.56
query11	0.21	0.14	0.14
query12	0.19	0.15	0.14
query13	0.48	0.47	0.48
query14	1.02	1.00	1.00
query15	0.61	0.58	0.59
query16	0.32	0.33	0.31
query17	1.13	1.16	1.10
query18	0.23	0.22	0.21
query19	1.99	1.96	1.95
query20	0.02	0.01	0.02
query21	15.48	0.20	0.14
query22	4.96	0.05	0.05
query23	16.13	0.32	0.12
query24	2.95	0.44	0.35
query25	0.13	0.05	0.05
query26	0.73	0.21	0.14
query27	0.05	0.04	0.05
query28	3.58	0.92	0.51
query29	12.47	4.12	3.22
query30	0.28	0.16	0.18
query31	2.77	0.62	0.31
query32	3.23	0.59	0.49
query33	3.18	3.15	3.20
query34	15.46	4.27	3.51
query35	3.56	3.54	3.55
query36	0.55	0.46	0.42
query37	0.09	0.07	0.06
query38	0.05	0.04	0.03
query39	0.04	0.03	0.04
query40	0.18	0.16	0.15
query41	0.08	0.03	0.02
query42	0.04	0.02	0.03
query43	0.04	0.04	0.04
Total cold run time: 96.88 s
Total hot run time: 24.99 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 77.78% (84/108) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.72% (30167/40372)
Line Coverage 58.70% (331032/563963)
Region Coverage 55.44% (277594/500719)
Branch Coverage 56.73% (122775/216407)

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review found three blocking issues that should be fixed before merge:

  1. The PAIMON_CPP FileScannerV2 exclusion does not match real FE Paimon scan params, so PAIMON_CPP JNI splits can still be routed into V2.
  2. Failed JNI Java cleanup is made non-retryable even though JniTableReader::close() leaves _closed false after failure.
  3. Adaptive batch sizing reaches Paimon JNI after Java open, too late to cap Paimon's first physical readBatch() size.

Checkpoint conclusions: the PR goal is only partially met because the lifecycle hardening and routing fixes still miss real execution paths. The change is focused, but the tests use simplified shapes that miss the FE-generated Paimon params, the real close-reset state transition, and Paimon's open-time batch option. No new lock-order or transaction/persistence issue was found. Mixed-version Paimon option fallback looks correct. Observability changes are not required, but M2 is a memory/performance correctness issue for the adaptive batch feature. Validation was static only, as the review prompt forbids builds and test execution.

Comment thread be/src/exec/operator/file_scan_operator.cpp Outdated
Comment thread be/src/format_v2/jni/jni_table_reader.cpp Outdated
Comment thread be/src/format_v2/jni/jni_table_reader.cpp
### What problem does this PR solve?

Issue Number: N/A

Related PR: apache#65503

Problem Summary: Paimon C++ splits could still enter FileScannerV2 because scanner selection inspected a scan-level table-format descriptor that FE only sends per split. Failed JNI cleanup also discarded the Java object before a retry, and adaptive JNI sizing was applied after Paimon had already opened its physical reader. Use the scan-level Paimon predicate marker for routing, retain JNI state until cleanup succeeds, and seed adaptive batch sizing before split preparation opens JNI readers.

### Release note

Ensure Paimon C++ scans use the supported scanner path, JNI cleanup remains retryable, and the first Paimon JNI batch honors adaptive sizing.

### Check List (For Author)

- Test: Unit Test
    - Remote ASAN BE unit tests: FileScannerV2Test.PaimonCppReaderForcesLegacyScanner and JniTableReaderTest.* (6 tests passed)
    - Remote build-support/check-format.sh passed with clang-format 16
    - Remote ASAN_UT changed objects compiled successfully
    - Remote clang-tidy analyzers completed for changed production files; final wrapper summary was not captured after the SSH output channel ended
- Behavior changed: Yes, scanner routing, JNI cleanup retry state, and first-batch sizing are corrected
- Does this need documentation: No
@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed after 2 rounds. All five subagents converged on this final M1/M2 comment set with NO_NEW_VALUABLE_FINDINGS.

I found two blocking issues: one compatibility gap in the Paimon CPP V1/V2 selection, and one lifecycle gap where the new JNI close retry state cannot be reached through the scanner close path. I did not duplicate existing review threads for the prior first-Paimon-JNI-batch timing concern or the inner JNI close-state retryability thread.

Critical checkpoint conclusions:

  • Goal: the PR addresses current-FE Paimon selection, JNI cleanup, cancellation, and adaptive batch feedback, but still misses rolling-upgrade Paimon CPP split-level metadata and scanner-level close retry.
  • Scope: mostly focused, but the close retry fix crosses the JniTableReader/FileScannerV2 lifecycle boundary.
  • Concurrency: no new shared-thread synchronization was added; the issue is lifecycle state ordering during close.
  • Lifecycle: not complete; FileScannerV2 marks itself closed before retained JNI cleanup state can be retried.
  • Configuration: no new config.
  • Compatibility: not complete for old FE/new BE Paimon CPP shapes that keep Paimon metadata only at split level.
  • Parallel paths: Paimon/Hudi hybrid batch forwarding was reviewed; no additional adaptive-batch issue found after the current seeding change.
  • Tests: new BE tests are discovered by the existing CMake glob, but coverage is still missing for the accepted Paimon CPP rolling-upgrade selector and scanner-level failing-then-succeeding close path.
  • Observability/performance: warning/profile changes and adaptive-batch seeding look reasonable; no separate metrics issue found.
  • Transactions/persistence/data writes: not directly involved.
  • User focus: no additional user-provided review focus.

Validation: static review only per the review prompt; no builds or unit tests were run. git diff --check is clean in this checkout.

// FE stores Paimon's table-format descriptor per split, but paimon_predicate is a scan-level
// Paimon marker. PAIMON_CPP is also selected per split, and FileScannerV2 cannot dispatch that
// reader type, so retain the V1 path until the V2 hybrid reader supports it.
const bool uses_paimon_cpp_reader = scan_params.__isset.paimon_predicate &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exclusion still misses the rolling-upgrade shape where Paimon metadata is only on each split. This selector only sees TFileScanRangeParams, so an old FE that has enable_paimon_cpp_reader=true but still sends Paimon predicate/reader metadata only in TFileRangeDesc.table_format_params.paimon_params will leave scan_params.__isset.paimon_predicate false and V2 remains selected. The first FORMAT_JNI range with TPaimonReaderType::PAIMON_CPP is not supported by V2: FileScannerV2::is_supported() accepts Paimon JNI only for PAIMON_JNI, and PaimonHybridReader dispatches only PAIMON_JNI to the JNI child. Please either use a marker that is guaranteed for both current and rolling-upgrade Paimon CPP scans, or conservatively keep JNI Paimon CPP on V1 until the split-level reader type can be inspected, and add a test for scan params without scan-level paimon_predicate plus a split-level PAIMON_CPP range.

Comment thread be/src/format_v2/jni/jni_table_reader.cpp
@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 29530 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 52bda3f2c241f23986c5350bfbf636b9afa9687c, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17675	4054	4025	4025
q2	2037	329	211	211
q3	10253	1466	874	874
q4	4689	518	335	335
q5	7563	943	581	581
q6	202	171	138	138
q7	782	825	635	635
q8	9920	1612	1554	1554
q9	6034	4380	4372	4372
q10	6812	1833	1540	1540
q11	509	341	316	316
q12	743	549	431	431
q13	18114	3357	2791	2791
q14	268	262	248	248
q15	q16	788	784	720	720
q17	1362	1120	822	822
q18	6818	5783	5608	5608
q19	1743	1321	1063	1063
q20	751	662	557	557
q21	6051	2597	2405	2405
q22	437	364	304	304
Total cold run time: 103551 ms
Total hot run time: 29530 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4419	4301	4350	4301
q2	295	320	224	224
q3	4543	4939	4376	4376
q4	2067	2141	1369	1369
q5	4431	4369	4293	4293
q6	234	182	131	131
q7	2282	1947	1716	1716
q8	2530	2308	2225	2225
q9	8276	7826	7767	7767
q10	4729	4671	4231	4231
q11	577	436	399	399
q12	810	817	589	589
q13	3244	3618	2989	2989
q14	281	310	281	281
q15	q16	739	764	626	626
q17	1376	1471	1309	1309
q18	7910	7272	7263	7263
q19	1102	1055	1067	1055
q20	2219	2230	1947	1947
q21	5243	4608	4510	4510
q22	542	462	388	388
Total cold run time: 57849 ms
Total hot run time: 51989 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 181365 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 52bda3f2c241f23986c5350bfbf636b9afa9687c, data reload: false

query5	4318	637	486	486
query6	457	219	203	203
query7	4839	593	348	348
query8	335	196	174	174
query9	8773	4151	4114	4114
query10	452	390	278	278
query11	5903	2372	2208	2208
query12	162	102	101	101
query13	1271	625	431	431
query14	6295	5366	5013	5013
query14_1	4359	4337	4358	4337
query15	227	218	180	180
query16	1032	489	454	454
query17	1144	764	597	597
query18	2458	491	358	358
query19	214	196	153	153
query20	114	107	108	107
query21	226	165	143	143
query22	13766	13749	13542	13542
query23	17305	16519	16293	16293
query23_1	16339	16311	16237	16237
query24	7505	1775	1302	1302
query24_1	1332	1295	1292	1292
query25	565	474	403	403
query26	1339	373	225	225
query27	2575	568	388	388
query28	4492	2027	2032	2027
query29	1109	649	510	510
query30	347	263	226	226
query31	1131	1099	985	985
query32	108	65	67	65
query33	534	329	260	260
query34	1143	1134	661	661
query35	774	782	693	693
query36	1409	1448	1213	1213
query37	153	109	97	97
query38	1870	1697	1686	1686
query39	933	914	892	892
query39_1	875	875	892	875
query40	246	198	139	139
query41	68	67	62	62
query42	97	91	92	91
query43	336	332	286	286
query44	1474	794	774	774
query45	204	188	181	181
query46	1081	1223	784	784
query47	2326	2315	2244	2244
query48	410	433	264	264
query49	585	431	323	323
query50	1045	417	345	345
query51	11018	10685	10774	10685
query52	92	85	78	78
query53	264	277	202	202
query54	283	226	225	225
query55	79	78	66	66
query56	309	304	293	293
query57	1419	1395	1319	1319
query58	280	278	259	259
query59	1616	1677	1445	1445
query60	320	264	245	245
query61	150	148	160	148
query62	703	646	580	580
query63	246	212	214	212
query64	2818	1050	831	831
query65	4880	4842	4803	4803
query66	1819	508	388	388
query67	29547	29516	29339	29339
query68	3224	1541	923	923
query69	410	301	266	266
query70	1115	967	987	967
query71	367	340	300	300
query72	3006	2663	2402	2402
query73	828	822	447	447
query74	5147	4979	4766	4766
query75	2618	2591	2236	2236
query76	2320	1196	761	761
query77	356	394	313	313
query78	12192	12454	11865	11865
query79	1376	1164	777	777
query80	1252	547	473	473
query81	524	320	280	280
query82	635	159	124	124
query83	371	320	291	291
query84	277	163	131	131
query85	951	643	498	498
query86	432	304	296	296
query87	1826	1832	1738	1738
query88	3770	2842	2779	2779
query89	460	401	359	359
query90	1953	222	207	207
query91	198	201	161	161
query92	64	62	55	55
query93	1680	1486	970	970
query94	714	362	317	317
query95	789	609	462	462
query96	1034	831	354	354
query97	2683	2701	2571	2571
query98	214	207	198	198
query99	1169	1165	1016	1016
Total cold run time: 266372 ms
Total hot run time: 181365 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 25.09 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 52bda3f2c241f23986c5350bfbf636b9afa9687c, data reload: false

query1	0.01	0.01	0.01
query2	0.09	0.06	0.05
query3	0.27	0.14	0.14
query4	1.60	0.13	0.14
query5	0.24	0.23	0.23
query6	1.28	1.04	1.09
query7	0.04	0.01	0.01
query8	0.06	0.03	0.04
query9	0.39	0.32	0.35
query10	0.58	0.61	0.55
query11	0.19	0.14	0.14
query12	0.19	0.15	0.14
query13	0.48	0.48	0.48
query14	1.02	1.02	1.02
query15	0.62	0.59	0.59
query16	0.32	0.35	0.32
query17	1.13	1.12	1.11
query18	0.24	0.23	0.22
query19	2.02	1.98	1.89
query20	0.01	0.02	0.01
query21	15.44	0.22	0.13
query22	4.80	0.05	0.05
query23	16.12	0.30	0.12
query24	2.98	0.41	0.33
query25	0.11	0.06	0.04
query26	0.71	0.21	0.14
query27	0.04	0.04	0.04
query28	3.57	0.93	0.55
query29	12.53	4.07	3.24
query30	0.29	0.17	0.15
query31	2.77	0.59	0.31
query32	3.23	0.60	0.48
query33	3.16	3.23	3.24
query34	15.57	4.26	3.51
query35	3.52	3.55	3.54
query36	0.56	0.44	0.44
query37	0.10	0.07	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.02
query40	0.18	0.17	0.15
query41	0.08	0.03	0.03
query42	0.03	0.03	0.03
query43	0.05	0.03	0.04
Total cold run time: 96.71 s
Total hot run time: 25.09 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 59.56% (81/136) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 56.92% (23558/41386)
Line Coverage 40.58% (230285/567551)
Region Coverage 36.46% (181893/498834)
Branch Coverage 37.56% (81244/216331)

### What problem does this PR solve?

Issue Number: None

Related PR: apache#65503

Problem Summary: FileScannerV2 selection could still route rolling-upgrade Paimon CPP JNI splits into an unsupported V2 reader, and a failed table-reader close left the scanner marked closed so retained JNI cleanup state could not be retried. Conservatively keep JNI scans on V1 while the Paimon C++ reader option is enabled, and roll back the scanner close guard when table-reader cleanup fails.

### Release note

Harden Paimon CPP scanner selection and retry JNI cleanup after close failures.

### Check List (For Author)

- Test: Unit Test

    - FileScannerV2Test.* and JniTableReaderTest.*: 20 tests passed under ASAN BE UT

- Behavior changed: Yes. Unsupported Paimon CPP JNI splits stay on V1, and failed V2 table-reader cleanup can be retried.

- Does this need documentation: No
@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes based on static review.

Critical checkpoint conclusions:

  • Goal: the PR addresses several prior JNI/FileScannerV2 review issues, but three compatibility/lifecycle/resource issues remain.
  • Scope: the changes are focused on scanner selection, JNI cleanup, adaptive batch sizing, hybrid readers, and BE tests.
  • Concurrency/lifecycle: scanner close retry and JNI resource lifecycle were reviewed; Paimon Java cleanup still invalidates retry state.
  • Compatibility: rolling-upgrade Paimon JNI without reader_type is still not preserved on the V2 path.
  • Parallel paths: FileScannerV1, FileScannerV2, Paimon/Hudi hybrid readers, and representative Java JNI scanners were checked.
  • Testing: new BE tests cover useful cases, but they miss the three accepted edge cases below.
  • Configuration/storage/transactions/observability: no new config, storage format, transaction, or observability requirement was found.

User focus: no additional user-provided focus was supplied.

Validation: static review only. I did not run builds or tests because the review prompt forbids build/test operations in this runner; the checkout also lacks .worktree_initialized and thirdparty/installed.

Comment thread be/src/exec/operator/file_scan_operator.cpp Outdated
Comment thread be/src/format_v2/jni/jni_table_reader.cpp
Comment thread be/src/format_v2/jni/jni_table_reader.cpp
### What problem does this PR solve?

Issue Number: None

Related PR: apache#65503

Problem Summary: Legacy Paimon JNI splits without reader_type could still enter FileScannerV2, adaptive batch-size updates after open did not resize Paimon physical readers, and failed Java cleanup cleared resource references before a retry. Keep JNI compatibility shapes on the legacy scanner, preserve the initial Paimon physical batch size after open, and retain each Java resource until its cleanup succeeds.

### Release note

Harden legacy JNI selection, Paimon batch-size handling, and retryable Java cleanup.

### Check List (For Author)

- Test: Unit Test

    - FileScannerV2Test.*, JniTableReaderTest.*, and PaimonJniReaderTest.*: 30 tests passed under ASAN BE UT
    - PaimonJniScannerTest: 10 tests passed; checkstyle reported 0 violations
    - clang-format and git diff checks passed

- Behavior changed: Yes. Legacy JNI compatibility splits stay on V1, Paimon ignores unsupported post-open physical batch resizing, and failed Java cleanup remains retryable.

- Does this need documentation: No
@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review completed for PR 65503.

I found one remaining issue worth requesting changes for: retryable JNI close failures can double-publish the same split profile counters/statistics before a later close succeeds.

Checkpoint summary:

  • Goal/test evidence: the PR addresses JNI scanner lifecycle, FileScannerV2 selection compatibility, adaptive batch sizing, and Paimon Java cleanup retry behavior with focused BE and Java tests in the patch.
  • Scope/focus: the change is focused on scanner/JNI lifecycle and compatibility paths; the broad scan-level FORMAT_JNI fallback was reviewed and treated as a conservative fallback because V1 has matching non-Paimon JNI reader coverage and adaptive batch forwarding.
  • Concurrency/lifecycle: close retry state was reviewed through FileScannerV2, JniTableReader, hybrid readers, and Paimon Java resources. The resource-retention path is now retryable, but the profile-publication side effect below remains.
  • Compatibility/parallel paths: Paimon scan-level versus split-level predicate/options/Hadoop-conf fallback was compared against the legacy V1 reader. The plugin-driven no-filter Paimon predicate omission found during review is in unchanged provider code and is out of this PR's patch scope.
  • Tests: added tests cover the main selector, retry, EOF/cancellation, adaptive batch, and Paimon fallback paths. I did not run builds/tests in this review runner, per the review prompt; validation was static. The saved patch applies cleanly in reverse with whitespace checking.
  • User focus: no additional user-provided review focus was supplied.

All round-1 subagents and risk-focused subagents converged on this exact final comment set with NO_NEW_VALUABLE_FINDINGS.

Comment thread be/src/format_v2/jni/jni_table_reader.cpp
### What problem does this PR solve?

Issue Number: None

Related PR: apache#65503

Problem Summary: A retryable JNI scanner close published the same split profile on every cleanup attempt because the Java scanner and watcher values must remain intact after a failed close. Reserve profile publication per split so close retries only repeat resource cleanup, then reset that publication state when the split is successfully released.

### Release note

Keep JNI split profile counters idempotent across close retries.

### Check List (For Author)

- Test: Unit Test

    - FileScannerV2Test.*, JniTableReaderTest.*, and PaimonJniReaderTest.*: 30 tests passed under ASAN BE UT
    - FailedCloseCanBeRetried asserts the close profile counter is unchanged after a fail-then-success retry
    - check-format and git diff checks passed

- Behavior changed: Yes. Retried JNI cleanup no longer publishes the same split profile more than once.

- Does this need documentation: No
@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 29512 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 68655aebade5fe2cf92f8a045c125017555ffe31, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17990	4106	4031	4031
q2	2043	323	196	196
q3	10289	1441	841	841
q4	4682	468	341	341
q5	7509	870	590	590
q6	183	174	140	140
q7	792	828	618	618
q8	9342	1561	1601	1561
q9	5611	4377	4381	4377
q10	6764	1805	1534	1534
q11	505	339	320	320
q12	710	541	426	426
q13	18067	3431	2787	2787
q14	271	262	241	241
q15	q16	790	797	715	715
q17	944	983	1036	983
q18	7112	5764	5572	5572
q19	1327	1279	1061	1061
q20	763	641	555	555
q21	5939	2583	2318	2318
q22	424	349	305	305
Total cold run time: 102057 ms
Total hot run time: 29512 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4335	4252	4259	4252
q2	289	336	210	210
q3	4579	5016	4368	4368
q4	2051	2155	1350	1350
q5	4451	4314	4310	4310
q6	228	180	134	134
q7	1727	1962	1876	1876
q8	2580	2181	2196	2181
q9	8035	8274	7879	7879
q10	4758	4703	4300	4300
q11	563	421	384	384
q12	768	797	572	572
q13	3312	3623	2966	2966
q14	302	305	284	284
q15	q16	739	712	627	627
q17	1325	1300	1315	1300
q18	8075	7307	7340	7307
q19	1124	1082	1052	1052
q20	2209	2213	1950	1950
q21	5196	4551	4369	4369
q22	511	472	408	408
Total cold run time: 57157 ms
Total hot run time: 52079 ms

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 29489 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit c05c7b5389214a58609b9a7be95c9f3eaa897ade, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17716	4023	4031	4023
q2	2018	325	201	201
q3	10287	1416	812	812
q4	4678	482	342	342
q5	7500	846	592	592
q6	182	168	138	138
q7	750	836	629	629
q8	9335	1547	1561	1547
q9	5585	4412	4344	4344
q10	6748	1839	1549	1549
q11	498	357	330	330
q12	709	550	457	457
q13	18123	3410	2762	2762
q14	273	265	245	245
q15	q16	787	788	715	715
q17	995	1003	897	897
q18	7260	5821	5599	5599
q19	1311	1309	1025	1025
q20	778	653	538	538
q21	5906	2626	2438	2438
q22	436	357	306	306
Total cold run time: 101875 ms
Total hot run time: 29489 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4492	4401	4377	4377
q2	282	322	216	216
q3	4625	4976	4416	4416
q4	2080	2146	1372	1372
q5	4503	4408	4332	4332
q6	224	174	127	127
q7	1753	2039	1907	1907
q8	2547	2245	2371	2245
q9	8078	8353	7913	7913
q10	4782	4669	4273	4273
q11	576	401	385	385
q12	790	780	537	537
q13	3329	3666	2990	2990
q14	309	305	267	267
q15	q16	717	761	671	671
q17	1359	1351	1345	1345
q18	8064	7310	7286	7286
q19	1128	1125	1041	1041
q20	2208	2196	1949	1949
q21	5264	4584	4438	4438
q22	522	465	417	417
Total cold run time: 57632 ms
Total hot run time: 52504 ms

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one remaining issue in the Paimon JNI cleanup retry path.

The scanner-selection changes now keep scan-level FORMAT_JNI on the legacy path, which covers the Paimon CPP and missing-reader_type compatibility shapes already discussed in existing review threads. The C++ JNI close retry path now preserves JNI state, gates split profile publication, and reopens FileScannerV2 close for explicit retry. Adaptive batch sizing is seeded before eager JNI open and propagated through Paimon/Hudi hybrid children, with Paimon post-open resizing intentionally left unchanged.

Remaining issue: the Java Paimon close path preserves retryable resources after a failed cleanup, but still decrements the active-scanner gauge during that failed close. Please fix that before merging.

Validation: static review only. The PR head still matches c05c7b5. The checkout is shallow, so full local range checks and builds/tests were not run here. Added-line whitespace in the authoritative patch was checked, and git show --check HEAD reported no whitespace problems for the checked-out commit.

Review checkpoints: goal is mostly met but one observability/lifecycle issue remains; scope is focused; lifecycle and retry behavior were reviewed; no new configs or persistence formats; compatibility paths were checked against current and legacy Paimon shapes; tests cover most retry/routing/adaptive paths but miss the active-scanner metric assertion.

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 182194 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit c05c7b5389214a58609b9a7be95c9f3eaa897ade, data reload: false

query5	4313	637	498	498
query6	466	223	214	214
query7	4859	620	363	363
query8	343	192	176	176
query9	8804	4120	4117	4117
query10	454	349	297	297
query11	5951	2373	2206	2206
query12	158	104	108	104
query13	1291	600	424	424
query14	6233	5312	4941	4941
query14_1	4240	4271	4299	4271
query15	213	203	177	177
query16	1003	491	459	459
query17	946	722	584	584
query18	2432	471	346	346
query19	207	193	151	151
query20	116	108	105	105
query21	235	163	139	139
query22	13690	13560	13447	13447
query23	17478	16654	16248	16248
query23_1	16354	16474	16314	16314
query24	7514	1794	1305	1305
query24_1	1327	1338	1342	1338
query25	574	470	410	410
query26	1313	353	208	208
query27	2621	647	385	385
query28	4434	2051	2097	2051
query29	1078	661	503	503
query30	339	268	228	228
query31	1146	1113	987	987
query32	109	66	65	65
query33	562	333	265	265
query34	1218	1238	656	656
query35	785	781	682	682
query36	1400	1427	1221	1221
query37	170	115	96	96
query38	1872	1704	1653	1653
query39	937	929	905	905
query39_1	884	891	905	891
query40	247	162	141	141
query41	76	70	71	70
query42	98	93	96	93
query43	331	333	284	284
query44	1496	791	788	788
query45	210	194	183	183
query46	1091	1203	772	772
query47	2400	2344	2247	2247
query48	394	437	292	292
query49	582	441	337	337
query50	1123	430	336	336
query51	10866	10929	10933	10929
query52	95	92	84	84
query53	276	291	214	214
query54	315	252	237	237
query55	78	77	69	69
query56	316	310	322	310
query57	1468	1426	1329	1329
query58	296	302	288	288
query59	1616	1702	1473	1473
query60	320	287	267	267
query61	181	205	145	145
query62	704	659	606	606
query63	240	205	214	205
query64	2840	1053	859	859
query65	4880	4830	4790	4790
query66	1823	505	378	378
query67	29599	29582	29374	29374
query68	3240	1541	1011	1011
query69	400	307	272	272
query70	1095	1038	949	949
query71	383	326	303	303
query72	3079	2790	2432	2432
query73	815	781	435	435
query74	5136	4979	4792	4792
query75	2638	2612	2236	2236
query76	2327	1203	814	814
query77	357	390	300	300
query78	12294	12294	11737	11737
query79	1435	1224	761	761
query80	1320	529	472	472
query81	563	323	286	286
query82	638	159	123	123
query83	400	329	305	305
query84	337	156	131	131
query85	989	598	540	540
query86	441	307	291	291
query87	1838	1820	1753	1753
query88	3795	2836	2791	2791
query89	460	408	357	357
query90	1900	202	212	202
query91	206	192	175	175
query92	68	65	57	57
query93	1764	1554	988	988
query94	724	365	329	329
query95	798	504	556	504
query96	1071	797	342	342
query97	2694	2713	2581	2581
query98	224	209	201	201
query99	1158	1199	1066	1066
Total cold run time: 266749 ms
Total hot run time: 182194 ms

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage `` 🎉
Increment coverage report
Complete coverage report

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 25.04 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit c05c7b5389214a58609b9a7be95c9f3eaa897ade, data reload: false

query1	0.01	0.01	0.01
query2	0.10	0.05	0.05
query3	0.26	0.13	0.14
query4	1.61	0.15	0.14
query5	0.24	0.24	0.22
query6	1.23	1.06	1.10
query7	0.04	0.01	0.01
query8	0.06	0.03	0.04
query9	0.38	0.31	0.32
query10	0.55	0.60	0.55
query11	0.19	0.15	0.14
query12	0.19	0.15	0.14
query13	0.47	0.48	0.48
query14	1.04	1.01	1.02
query15	0.62	0.60	0.61
query16	0.30	0.31	0.33
query17	1.09	1.11	1.14
query18	0.23	0.21	0.22
query19	2.11	1.92	1.93
query20	0.02	0.01	0.01
query21	15.44	0.24	0.13
query22	4.69	0.05	0.05
query23	16.13	0.31	0.13
query24	2.98	0.49	0.34
query25	0.13	0.05	0.04
query26	0.72	0.21	0.14
query27	0.03	0.03	0.03
query28	3.57	0.95	0.54
query29	12.50	4.06	3.23
query30	0.28	0.16	0.17
query31	2.77	0.58	0.32
query32	3.22	0.60	0.49
query33	3.19	3.12	3.22
query34	15.56	4.29	3.53
query35	3.53	3.57	3.56
query36	0.55	0.45	0.43
query37	0.08	0.06	0.06
query38	0.06	0.05	0.03
query39	0.04	0.02	0.03
query40	0.19	0.17	0.15
query41	0.08	0.03	0.03
query42	0.04	0.03	0.03
query43	0.05	0.04	0.04
Total cold run time: 96.57 s
Total hot run time: 25.04 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 62.07% (108/174) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 56.94% (23575/41401)
Line Coverage 40.60% (230481/567704)
Region Coverage 36.50% (182106/498943)
Branch Coverage 37.59% (81336/216354)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 58.78% (87/148) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.78% (30203/40387)
Line Coverage 58.81% (331752/564130)
Region Coverage 55.52% (278069/500841)
Branch Coverage 56.82% (122977/216442)

@Gabriel39 Gabriel39 merged commit db72b96 into apache:master Jul 13, 2026
31 of 33 checks passed
hello-stephen pushed a commit that referenced this pull request Jul 13, 2026
### What problem does this PR solve?

Fix a BE UT compile failure introduced by the combination of #65500 and
#65503.
`SplitReadOptions` now has `conjuncts` and
`all_runtime_filters_applied`, while
the new `jni_table_reader_test.cpp` designated initializer did not
initialize
them. With `-Werror,-Wmissing-designated-field-initializers`, this fails
compilation.

This PR explicitly initializes the two fields in the test and adds the
missing
`<optional>` include for `std::nullopt`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants